package slap.mvc.result;

import java.util.Map;

import slap.exception.UnexpectedException;
import slap.http.Request;
import slap.http.Response;
import slap.http.StatusCode;
import slap.mvc.scope.Flash;
import slap.mvc.scope.RenderModels;
import slap.mvc.scope.Session;
import slap.util.MimeTypes;

/**
 * 403 Forbidden
 */
public class Forbidden extends Result {

    public Forbidden(String reason) {
        super(reason);
    }

    public void apply(Request request, Response response) {
        response.status = StatusCode.FORBIDDEN;
        
        Map<String, Object> binding = RenderModels.current().data;
        binding.put("result", this);
        binding.put("session", Session.current());
        binding.put("request", Request.current());
        binding.put("flash", Flash.current());
        String errorHtml = getMessage();
        try {
            response.out.write(errorHtml.getBytes("utf-8"));
        } catch (Exception e) {
            throw new UnexpectedException(e);
        }
    }
    
}
